package com.box.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.box.entity.DbAdmin;
import com.box.entity.DbPersonInfo;
import com.box.service.AdminService;
import com.box.service.PersonInfoService;
import com.box.utils.LayuiResult;

@Controller
@RequestMapping("/personinfo")
public class PersonInfoController {
	
	@Autowired
	private PersonInfoService personService;
	
	@Autowired
	private AdminService adminService;
	
	@RequestMapping(value="/personinfoList",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public LayuiResult selList(Integer page,Integer limit,HttpServletResponse response){
		 response.setHeader("Access-Control-Allow-Origin", "*");
		return personService.selPersonInfoList(page, limit);
	}
	
	@RequestMapping(value="/updPersonInfo",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public LayuiResult updPersonInfo(DbPersonInfo personinfo){
		Integer n = personService.updatePersonInfoByO(personinfo);
		if(n>0){
			return new LayuiResult(0, "修改成功");
		}else{
			return new LayuiResult(500,"修改失败");
		}
	
	}
	
	
	/**
	 * 
	 * 页面跳转
	 * 
	 * 
	 */
	
	@RequestMapping(value="/page/personinfo",method={RequestMethod.GET,RequestMethod.POST})
	public String  showPageList(Model model){
		DbAdmin admin = adminService.getDbAdminItems();
		model.addAttribute("admin", admin);
		return "personinfo/personinfo";
	}

	//修改个人信息
	@RequestMapping(value="/page/editpersoninfo/{id}",method={RequestMethod.GET,RequestMethod.POST})
	public String  updatePageInfo(@PathVariable("id") String id,Model model){
		DbAdmin admin = adminService.getDbAdminItems();
		model.addAttribute("admin", admin);
		DbPersonInfo person = personService.selPersonInfoById(id);
		model.addAttribute("person",person);
		return "personinfo/editPersoninfo";
	}

}
